<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title></title>
<!-- 引入EasyUI的相关css和js文件 -->
<link href="EasyUI/themes/default/easyui.css" rel="stylesheet"
	type="text/css" />
<link href="EasyUI/themes/icon.css" rel="stylesheet" type="text/css" />
<link href="EasyUI/demo.css" rel="stylesheet" type="text/css" />
<script src="EasyUI/jquery.min.js" type="text/javascript"></script>
<script src="EasyUI/jquery.easyui.min.js" type="text/javascript"></script>
<script src="EasyUI/easyui-lang-zh_CN.js" type="text/javascript"></script>
</head>
<body>

	<table id="dg_medicine" class="easyui-datagrid"></table>
	<!-- 添加确定保存处方订单对话框 -->
	<div id="dlg_savePrescription" class="easyui-dialog" title="保存处方"
		closed="true" style="width: 500px;">
		<div style="padding: 10px 60px 20px 60px">
			<div style="text-align: center; padding: 5px">
				确定要保存处方？（保存后不可更改，请确认）<br>
				<form id="ff_saveCheckPrescription" method="POST" action="">
					<td>病案号:</td>
					<td><input class="easyui-textbox" type="text"
						id="medicalrecord" name="medicalrecord" readonly="readonly"
						data-options="required:true"></input></td>
					<td>病人姓名:</td>
					<td><input class="easyui-textbox" type="text" id="patientname"
						name="patientname" readonly="readonly"
						data-options="required:true"></input></td>
				</form>
				<a href="javascript:void(0)" class="easyui-linkbutton"
					onclick="saveCheckPrescription();">保存</a>
			</div>
		</div>
	</div>
	<!-- 添加和删除用药商品对话框 -->
	<div id="dlg_Medicine" class="easyui-dialog" title="添加用药" closed="true"
		style="width: 500px;">
		<div style="padding: 10px 60px 20px 60px">
			<form id="ff_Medicine" method="POST" action="">
				<table cellpadding="5">
					<tr>
						<td>病案号:</td>
						<td><input class="easyui-textbox" type="text"
							id="medicalrecord" name="medicalrecord" readonly="readonly"
							data-options="required:true"></input></td>
					</tr>

					<tr>
						<td>药品名称:</td>
						<td>
							<!--  --> <input id="drugname" name="drugname">

						</td>
					</tr>

					<tr>
						<td>药品编码:</td>
						<td><input class="easyui-textbox" type="text" id="drugno"
							name="drugno" data-options="required:true" readonly="readonly"></input></td>
					</tr>

					<tr>
						<td>药品规格:</td>
						<td><input class="easyui-textbox" type="text"
							id="drugspecification" name="drugspecification"
							data-options="required:true" readonly="readonly"></input></td>
					</tr>
					<tr>
						<td>药品单价:</td>
						<td><input class="easyui-textbox" type="text" id="drugprice"
							name="drugprice" data-options="required:true" readonly="readonly"></input></td>
					</tr>
					<tr>
						<td>药品数量:</td>
						<td><input class="easyui-textbox" type="text" id="unit"
							name="unit" data-options="required:true"></input></td>
					</tr>

					<tr>
						<td>药品剂量:</td>
						<td><input class="easyui-textbox" type="text" id="dose"
							name="dose" data-options="required:true"></input></td>
					</tr>
					<tr>
						<td>每天用药次数:</td>

						<td>< <select class="easyui-combobox" name="usage" id="usage"
							data-options="required:true" ><option value="3小时一次">3小时一次</option>
								<option value="4小时一次">4小时一次</option>
								<option value="6小时一次">6小时一次</option>
								<option value="8小时一次">8小时一次</option>
								<option value="12小时一次">12小时一次</option>
								<option value="24小时一次">24小时一次</option>
								<option value="48小时一次">48小时一次</option>								
								</select></input></td>
					</tr>
					<!-- selectbox 
					<tr>
						<td>用药次数:</td>
						<td><input class="easyui-textbox" name="usage" id="usage"
							data-options="multiline:true" style="height: 60px"></input></td>
					</tr>
				-->
					<tr>
						<td>用药天数:</td>
						<td><input class="easyui-textbox" type="text" id="days"
							name="days" data-options="required:true"></input></td>
					</tr>
					<tr>
						<td>用药备注:</td>
						<td><input class="easyui-textbox" type="text"
							id="medicineremark" name="medicineremark"
							data-options="required:true"></input></td>
					</tr>

				</table>
			</form>
			<div style="text-align: center; padding: 5px">
				<a href="javascript:void(0)" class="easyui-linkbutton"
					onclick="saveMedicine();">保存</a>
			</div>
		</div>
	</div>
	<!-- 删除药品信息对话框 -->
	<div id="dlg_deletemedicine" class="easyui-dialog" title="删除药品"
		closed="true" style="width: 500px;">
		<div style="padding: 10px 60px 20px 60px">
			<div style="text-align: center; padding: 5px">
				确定要删除用药？<br>
				<form id="ff_deletemedicine" method="POST" action="">
					<td>药品名称:</td>
					<td><input class="easyui-textbox" type="text" id="drugname"
						name="drugname" readonly="readonly" data-options="required:true"></input></td>
				</form>
				<a href="javascript:void(0)" class="easyui-linkbutton"
					onclick="deleteMedicineDlg();">删除</a>
			</div>
		</div>
	</div>
	<!-- 创建datagrid控件的工具栏 -->
	<div id="tb_medicine" style="padding: 2px 5px;">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-add" plain="true" id="addPrescriptionDrug"
			onclick="addPrescriptionDrug();">添加用药</a><a href="javascript:void(0)"
			class="easyui-linkbutton" iconCls="icon-edit" plain="true"
			id="updatePrescriptionDrug" onclick="updatePrescriptionDrug();">修改用药</a><a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-remove" plain="true" id="removePrescriptionDrug"
			onclick="removePrescriptionDrug();">删除用药</a><a
			href="javascript:void(0)" class="easyui-linkbutton"
			id="savePrescription" iconCls="icon-save" plain="true"
			onclick="savePrescription();">保存处方</a>
	</div>

	<!-- 创建处方主表录入布局 -->
	<div id="divPrescriptionInfo">
		<form id="ff_addprescriptionFrom" method="post">
			<div style="margin-bottom: 20px">
				<input class="easyui-textbox" name="diagnosticcard"
					id="diagnosticcard"
					value="${sessionScope.prescription.diagnosticcard}"
					style="width: 40%" data-options="label:'诊疗卡号:'"> ---------
				<input class="easyui-textbox" name="sex" id="sex" style="width: 40%"
					value="${sessionScope.prescription.sex}" data-options="label:'性别:'">
			</div>
			<div style="margin-bottom: 20px">
				<input class="easyui-textbox" name="medicalrecord"
					id="medicalrecord"
					value="${sessionScope.prescription.medicalrecord}"
					style="width: 40%" data-options="label:'病案号:'"> --------- <input
					class="easyui-textbox" name="patientname" id="patientname"
					value="${sessionScope.prescription.patientname}" style="width: 40%"
					data-options="label:'病人姓名:'">
			</div>
			<div style="margin-bottom: 20px">
				<input class="easyui-textbox" name="age" id="age" style="width: 40%"
					value="${sessionScope.prescription.age}" data-options="label:'年龄:'">
				--------- <input class="easyui-textbox" name="phone" id="phone"
					style="width: 40%" value="${sessionScope.prescription.phone}"
					data-options="label:'手机号码:'">
			</div>
			<div style="margin-bottom: 20px">
				<input class="easyui-textbox" name="doctorname" id="doctorname"
					style="width: 40%" value="${sessionScope.doctor.doctorname}"
					data-options="label:'医生姓名:'"> --------- <input
					class="easyui-textbox" name="department" id="department"
					style="width: 40%" value="'${sessionScope.doctor.department}'"
					data-options="label:'科室:'">
			</div>
			<div style="margin-bottom: 20px">
				<input class="easyui-textbox" name="pastmedicalhistory"
					id="pastmedicalhistory" style="width: 40%; height: 60px"
					value="${sessionScope.prescription.pastmedicalhistory}"
					data-options="label:'既往病史:',multiline:true"> --------- <input
					class="easyui-datebox" label="就诊日期:" name="prescriptiontime"
					id="prescriptiontime" style="width: 35%;"
					value="<%=new Date().toLocaleString()%>">
			</div>
			<div style="margin-bottom: 20px">
				<input class="easyui-textbox" name="diagnosis" id="diagnosis"
					style="width: 80%; height: 60px"
					value="${sessionScope.prescription.diagnosis}"
					data-options="label:'诊断:',multiline:true">
			</div>
		</form>

	</div>
	<script type="text/javascript">
		// 加载com bobox
		/**/
		$('#drugname')
				.combobox(
						{
							//url:'drug/list',
							valueField : 'drugname',
							textField : 'drugname',
							editable : true,
							mode : 'remote',
							/*
							queryParems:{
								field:'drugname'
							},
							 */
							onSelect : function() {
								$
										.ajax({
											url : 'drug/list',
											dataType : 'json',
											data : {
												field : 'drugname',
												q : ''
											},
											success : function(data) {

												var box = $('#drugname')
														.combobox('getValue');
												for (i = 0; i < data.length; i++) {
													if (box == data[i].drugname) {
														$("#ff_Medicine")
																.form(
																		"load",
																		{
																			drugspecification : data[i].drugspecification,
																			drugno : data[i].drugno,
																			drugprice : data[i].drugprice,
																		});
													}
												}

											},

										});
							},

							loader : function(param, success, error) {
								var fd = param.field || 'drugname';
								var q = param.q || '';
								$
										.ajax({
											url : 'drug/list',
											data : {
												field : fd,
												q : q
											},
											dataType : 'json',
											success : function(data) {
												$('#drugname').combobox(
														'loadData', data);
												var box = $('#comboboxlist')
														.combobox('getValue');
												for (i = 0; i < data.length; i++) {
													if (box == data[i].drugname) {
														$("#ff_Medicine")
																.form(
																		"load",
																		{
																			drugspecification : data[0].drugspecification,
																			drugno : data[0].drugno,
																		});
													}
												}

											},

										});
							},
						})

		$(function() {
			$('#dg_medicine')
					.datagrid(
							{
								queryParams : {
									medicalrecord : '${sessionScope.prescription.medicalrecord}',
								},
								url : 'medicine/queryByMedicalrecord/',
								rownumbers : true,
								singleSelect : false,
								fit : true,
								toolbar : '#tb_medicine',
								header : '#divPrescriptionInfo',
								columns : [ [ {
									title : '序号',
									field : 'no',
									align : 'center',
									checkbox : true
								}, {
									field : 'drugno',
									title : '用药编号',
									width : 100,

								}, {
									field : 'drugname',
									title : '用药名称',
									width : 100,

								}, {
									field : 'drugprice',
									title : '单价',
									width : 80,

								}, {
									field : 'drugspecification',
									title : '规格',
									width : 100,

								}, {
									field : 'unit',
									title : '用药数量',
									width : 100,

								}, {
									field : 'dose',
									title : '剂量',
									width : 80,

								}, {
									field : 'usage',
									title : '每天用药次数',
									width : 120,

								}, {
									field : 'days',
									title : '用药天数',
									width : 80,

								}, {
									field : 'medicineremark',
									title : '备注',
									width : 120,

								} ] ]
							});
			//$('#1').linkbutton('disable'); 		
		});

		// 打开新增用药对话框
		function addPrescriptionDrug() {
			$('#dlg_Medicine').dialog('open').dialog('setTitle', '新增用药');
			$('#ff_Medicine').form('clear');

			$("#drugname").combobox('readonly', false);
			$('ff_Medicine').form('reset');
			$("#ff_Medicine").form("load", {
				medicalrecord : '${sessionScope.prescription.medicalrecord}',
			});

			urls = 'medicine/addmedicine';
		}
		//打开修改用药对话框
		function updatePrescriptionDrug() {
			var rows = $("#dg_medicine").datagrid('getSelections');
			if (rows.length > 0) {
				$("#drugname").combobox('readonly', true);
				var row = $("#dg_medicine").datagrid("getSelected");
				if (row) {
					$("#dlg_Medicine").dialog("open").dialog('setTitle',
							'修改用药信息');

					$("#ff_Medicine")
							.form(
									"load",
									{
										medicalrecord : '${sessionScope.prescription.medicalrecord}',
										"drugname" : row.drugname,
										"drugno" : row.drugno,
										"drugspecification" : row.drugspecification,
										"drugprice" : row.drugprice,
										"unit" : row.unit,
										"dose" : row.dose,
										"usage" : row.usage,
										"days" : row.days,
										"medicineremark" : row.medicineremark,

									});

					urls = "";
				}
			} else {
				$.messager.alert('提示', '请选择要修改的行', 'info');
			}
		}
		//保存信息
		function saveMedicine() {
			$("#ff_Medicine").form("submit", {
				url : urls, //使用参数				
				success : function(result) {
					var result = eval('(' + result + ')');
					if (result.success == 'true') {
						$("#dg_medicine").datagrid("reload");
						$("#dlg_Medicine").dialog("close");
					}
					$.messager.show({
						title : "提示信息",
						msg : result.message
					});
				}
			});
		}

		//删除用药打开提示框
		function removePrescriptionDrug() {

			var row = $("#dg_medicine").datagrid("getSelected");
			var rows = $("#dg_medicine").datagrid('getSelections');
			if (rows.length > 0) {
				var row = $("#dg_medicine").datagrid("getSelected");
				if (row) {
					$('#dlg_deletemedicine').dialog('open').dialog('setTitle',
							'删除用药');
					$("#ff_deletemedicine").form("load", {

						"drugname" : row.drugname,

					});
					urls = "medicine/deletemedicine";
				}
			} else {
				$.messager.alert('提示', '请选择要删除的行', 'info');
			}

		}
		//删除用药确认框
		function deleteMedicineDlg() {
			$("#ff_deletemedicine").form("submit", {
				url : urls, //使用参数				
				success : function(result) {
					var result = eval('(' + result + ')');
					if (result.success == 'true') {
						$("#dg_medicine").datagrid("reload");
						$("#dlg_deletemedicine").dialog("close");
					}
					$.messager.show({
						title : "提示信息",
						msg : result.message
					});
				}
			});
		}
		//保存处方
		function savePrescription() {
			$('#dlg_savePrescription').dialog('open')
					.dialog('setTitle', '保存处方');
			//$('#ff_Medicine').form('clear');			
			$("#ff_saveCheckPrescription").form("load", {
				medicalrecord : '${sessionScope.prescription.medicalrecord}',
				patientname : '${sessionScope.prescription.patientname}',
			});

			urls = 'prescription/addpresciption';
		}
		function saveCheckPrescription() {
			$("#ff_addprescriptionFrom").form("submit", {

				url : urls,
				success : function(result) {
					var result = eval('(' + result + ')');
					if (result.success == 'true') {
						$("#dlg_savePrescription").dialog("close");
						//显示成功信息
						$.messager.show({
							title : "提示信息",
							msg : result.message,
							style : {
								right : '',
								bottom : ''
							}
						});
						//成功后关闭选项卡
						if ($('#tabs').tabs('exists', '新建处方')) {
							$('#tabs').tabs('close', '新建处方');
						}
					} else {
						$.messager.show({
							title : "提示信息",
							msg : result.message
						});
					}
				}
			});
		}
	</script>
</body>
</html>